package ua.simplecoding.kievhome.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.stereotype.Service;
import ua.simplecoding.kievhome.converter.AppartmentSummaryVOConverter;
import ua.simplecoding.kievhome.dao.IAppartmentDao;
import ua.simplecoding.kievhome.domain.Appartment;
import ua.simplecoding.kievhome.filter.AppartmentFilterVO;
import ua.simplecoding.kievhome.vo.AppartmentSummaryVO;

import java.util.Arrays;
import java.util.List;

@Service(value = "appartmentService")
@RemotingDestination(channels = {"my-prefered-channel"})
public class AppartmentService implements IAppartmentService {

    @Autowired
    private IAppartmentDao appartmentDao;

    public Integer getTotalCount(int cityId) {
        return appartmentDao.getCount(cityId);
    }

    public List<Appartment> getAppartmentsByFilter(AppartmentFilterVO appartmentFilterVO) {
        return appartmentDao.search(appartmentFilterVO);
    }

    @Override
    public List<AppartmentSummaryVO> getAppartmentSummaryListByFilter() {
        List<Appartment> appartments = appartmentDao.search(new AppartmentFilterVO());

        List<AppartmentSummaryVO> summaryList = new AppartmentSummaryVOConverter().convert(appartments);

        return summaryList;
    }
}
